package com.yf.tool;

import com.yf.constants.VvHanConstants;
import com.yf.tool.model.dto.HoroscopeResponseDTO;
import com.yf.tool.model.request.WeatherRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

import java.util.function.Function;

/**
 * HoroscopeInfo Tool -- vv han code : 522
 */
@Deprecated
@Component
@RequiredArgsConstructor
public class HoroscopeInfoTool implements Function<WeatherRequest,
        HoroscopeResponseDTO.HoroscopeInfoDTO> {

    private final RestClient restClient = RestClient.create();

    /**
     * 获取星座运势信息
     *
     * @param weatherRequest the function argument
     * @return HoroscopeResponseDTO.HoroscopeInfoDTO
     */
    @Override
    public HoroscopeResponseDTO.HoroscopeInfoDTO apply(WeatherRequest weatherRequest) {
        String time = weatherRequest.getTime();
        String type = weatherRequest.getType();
        // 适配响应内容
        HoroscopeResponseDTO response = restClient.get()
                .uri(VvHanConstants.VV_HAN_HOST + VvHanConstants.HoroscopeEnums.HOROSCOPE.getUrl() + "?type={type}&time={time}", type, time)
                .retrieve()
                .body(HoroscopeResponseDTO.class);

        return response.getSuccess() ? response.getData() : null;
    }

}

